package com.example.curriculum.controller;

import com.example.curriculum.pojo.ResponseMessage;
import com.example.curriculum.pojo.User;
import com.example.curriculum.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/User")
public class UserController {
    @Resource
    private UserService userService;

    @PostMapping
    public ResponseMessage<User> add(@Validated @RequestBody User user){
        User usernew = userService.add(user);
        return ResponseMessage.success(usernew);
    }
    @GetMapping({"/{user_id}"})
    public ResponseMessage<User> select(@PathVariable String user_id){
        User usernew = userService.select(user_id);
        return ResponseMessage.success(usernew);
    }
    @PutMapping
    public ResponseMessage<User> update(@Validated @RequestBody User user){
        User usernew = userService.update(user);
        return ResponseMessage.success(usernew);
    }
    @DeleteMapping({"/{user_id}"})
    public ResponseMessage<User> delete(@PathVariable String user_id){
        userService.delete(user_id);
        return ResponseMessage.success();
    }
}
